package com.suoyue.store.controller;

import com.suoyue.store.entity.CartObject;
import com.suoyue.store.entity.Log;
import com.suoyue.store.entity.Order;
import com.suoyue.store.entity.Report;
import com.suoyue.store.service.iCartService;
import com.suoyue.store.service.iLogService;
import com.suoyue.store.service.iOrderService;
import com.suoyue.store.service.iReportService;
import com.suoyue.store.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("log")
public class LogController extends BaseController{

    @Autowired
    private iLogService logService;
    @Autowired
    private iReportService reportService;
    @Autowired
    private iOrderService orderService;
    @RequestMapping("getLog")
    public JsonResult<List<Log>> getLogByUid(Integer uid) {
        // 调用业务对象执行查询数据
        List<Log> data = logService.getLogByUid(uid);
//        System.out.println(data.get(0).getTime().toString());
        // 返回成功与数据
        return new JsonResult<List<Log>>(OK, data);
    }

    @RequestMapping("insertBrowse")
    public JsonResult<String> insert(HttpSession session,Integer pid){
        Integer uid=getUidFromSession(session);
        logService.insertBrowseLog(uid,pid);
        return new JsonResult<String>(OK);
    }


    @RequestMapping("getReport")
    public JsonResult<List<Report>> getReport(){
        List<Report> data=reportService.getReportData();
        return new JsonResult<List<Report>>(OK,data);
    }

    @RequestMapping("getProductReport")
    public JsonResult<List<Order>> getProductReport(Integer pid){
        List<Order> data=orderService.getListByPid(pid);
        return new JsonResult<List<Order>>(OK,data);
    }

    @RequestMapping("getOrderByUid")
    public JsonResult<List<Order>> getOrderList(Integer uid){
        List<Order> data=orderService.getListByUid(uid);
        return new JsonResult<List<Order>>(OK,data);
    }

    @RequestMapping("getDayReport")
    public JsonResult<Report> getOrderList(String day){
        Report data=reportService.getDayReport(day);
        return new JsonResult<Report>(OK,data);
    }


}
